<!--
 * @Description: 你的代码我的心
 * @Author: GGB
 * @Date: 2021-12-02 11:47:45
 * @LastEditors: GGB
 * @LastEditTime: 2021-12-08 17:27:52
-->
<template>
  <div class="container-box">
    <div class="header-box">
      <div class="header">
        <div class="logo">阳光沙滩-券场</div>
        <div class="nav">
          <nuxt-link
            class="link"
            v-for="nav in navs"
            :key="nav.url"
            :to="nav.url"
          >
            <div
              @click="active = nav.url"
              :class="[nav.url === active ? 'nav-active' : '', 'nav-item']"
            >
              {{ nav.name }}
            </div>
          </nuxt-link>
        </div>
        <el-input
          size="small"
          v-model="keyword"
          @clear="clear"
          clearable
          placeholder="请输入内容"
        />
        <el-button size="small" type="danger" @click="search">搜索</el-button>
      </div>
    </div>
    <Nuxt class="content" />
    <div class="footer-box">
      <div class="footer">
        <div class="item">联系我们</div>
        <div class="item">人才招聘</div>
        <div class="item">广告投放</div>
        <div class="item">常见问题</div>
        <div class="item">友情链接</div>
      </div>
      <div class="icp">
        ©2019 taobaounion.cn 粤IPC备 1209832号-11 code by TrillGates
      </div>
    </div>
  </div>
</template>
<script>
import {
  infiniteScroll,
  infiniteScrollDisabled,
  infiniteScrollDistance,
} from "@/directive/scroll";
export default {
  directives: {
    infiniteScroll,
    infiniteScrollDisabled,
    infiniteScrollDistance,
  },
  data() {
    return {
      navs: [
        {
          name: "发现",
          url: "/",
        },
        {
          name: "券场",
          url: "/ticket",
        },
        {
          name: "特惠",
          url: "/sell",
        },
      ],
      active: "/",
      keyword: "",
    };
  },
  watch: {
    $route(to, from) {
      if (to?.path) return (this.active = to.path);
      this.active = from.path;
    },
  },
  mounted() {
    if ($nuxt.$route.path) this.active = $nuxt.$route.path;
    this.keyword = $nuxt.$route.query.keyword || "";
  },
  methods: {
    loadMore() {
      console.log("test");
    },
    clear() {
      this.active === "/search" && this.$router.go(-1);
    },
    search() {
      if (this.keyword === "") return this.$message.error("搜索关键字不能为空");
      this.active === "/search"
        ? this.$router.replace(`/search?keyword=${this.keyword}`)
        : this.$router.push(`/search?keyword=${this.keyword}`);
    },
  },
};
</script>
<style lang="scss" scoped>
.container-box {
  // .content {
  //   // flex: 1;
  //   // overflow: hidden;
  //   // height: 100%;
  // }
  display: flex;
  flex-direction: column;
  .header-box {
    box-shadow: 0 5px 10px #d4d4d4;
    background-color: #fff;
    height: 70px;
    .header {
      width: 1140px;
      margin: 0 auto;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: flex-start;
      .logo {
        font-size: 24px;
        line-height: 70px;
        font-weight: 600;
        color: #c9302c;
      }
      .nav {
        margin-left: 30px;
        display: flex;
        flex-direction: row;
        align-items: center;
        margin-right: 30px;
        .link {
          text-decoration: none;
          color: #000;
          .nav-item {
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            line-height: 70px;
            padding-left: 15px;
            padding-right: 15px;

            &:hover {
              background-color: rgba(0, 0, 0, 0.03922);
            }
          }
          .nav-active {
            background: rgba(0, 0, 0, 0.03922);
          }
        }
      }
      .el-button--danger {
        width: 100px;
        margin-left: 20px;
      }
      .el-input {
        width: 300px;
      }
    }
  }
  .footer-box {
    margin-top: 0;
    color: #fff;
    padding: 20px 0px;
    background: #c9302c;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    .footer {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      width: 1140px;
      .item {
        padding-left: 10px;
        padding-right: 10px;
        margin-left: 10px;
        margin-right: 10px;
        line-height: 30px;
        cursor: pointer;
      }
    }
    .icp {
      line-height: 30px;

      text-align: center;
    }
  }
}
</style>